package com.beemans.admob.ads;

import android.content.Context;

import androidx.annotation.NonNull;

public final class AbAdvertUtils {

    /**
     * px 转 dp
     */
    public static float pxToDp(@NonNull Context context, float px) {
        final float density = context.getResources().getDisplayMetrics().density;
        return px / density;
    }

    /**
     * dp 转 px
     */
    public static float dpToPx(@NonNull Context context, float dp) {
        final float density = context.getResources().getDisplayMetrics().density;
        return dp * density;
    }

    /**
     * px 转 sp
     */
    public static float pxToSp(@NonNull Context context, float px) {
        final float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
        return px / scaledDensity;
    }

    /**
     * sp 转 px
     */
    public static float spToPx(@NonNull Context context, float sp) {
        final float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
        return sp * scaledDensity;
    }
}